﻿using System.Windows.Controls;
using System.Windows.Input;
using Apps.Yunwei.ViewModels;
using Apps.Yunwei.YunWeiService;
using Microsoft.Windows;
using QDP.Platform.ObjService;
using QDP.Platform.Services;
using Services.Maps;

namespace Apps.Yunwei
{
    public partial class MapBrowser : UserControl
    {
        public MapBrowser()
        {
            InitializeComponent();
            this.Loaded += WidgetLoad;
        }

        void WidgetLoad(object sender, System.Windows.RoutedEventArgs e)
        {
            (this.DataContext as MapBrowserViewModel).SetConfig(this.GetConfigs());
            this.Loaded -= WidgetLoad;
        }

        private void ListBoxDragDropTarget_Drop(object sender, DragEventArgs e)
        {

        }

        private void ListBoxDragDropTarget_ItemDroppedOnTarget(object sender, ItemDragEventArgs e)
        {
            dynamic dynamic = e.Data;
            if (dynamic[0].Item is ServiceObject)
            {
                var obj = dynamic[0].Item as ServiceObject;
                var imap = ServiceLoader.Load<IMapService>();

                imap.ImportService(new ServiceLayer()
                {
                    Caption = obj.Caption,
                    Url = obj.URL,
                    Type = obj.Type,
                    Code = obj.Code,
                });
            }
        }

        private void ListBoxDragDropTarget_ItemDragCompleted(object sender, ItemDragEventArgs e)
        {

        }

    }
}
